#include <iostream>
using namespace std;
int a[105];
int main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		int maxres=-0x3f3f3f3f;
		for(int i=0;i<(1<<n);i++)
		{
			int lastr=0,lastb=0;
			int res=0;
			for(int j=1;j<=n;j++)
			{
				if(i&(1<<(j-1)))
				{
					if(a[lastb]==a[j]) res+=a[j];
					lastb=j;
				}
				else
				{
					if(a[lastr]==a[j]) res+=a[j];
					lastr=j;
				}
			}
			maxres=max(maxres,res);
		}
		cout<<maxres<<endl;
	}
	return 0;
}
